using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PauseMenuController : MonoBehaviour
{
    [SerializeField] private GameObject pauseMenuUI; // 关联UI菜单的GameObject
    private bool isPaused = false;

    void Update()
    {
        // 检测是否按下ESC键
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (isPaused)
            {
                ResumeGame();
            }
            else
            {
                PauseGame();
            }
        }
    }

    // 暂停游戏并显示UI菜单
    private void PauseGame()
    {
        pauseMenuUI.SetActive(true); // 显示UI菜单
        Time.timeScale = 0f; // 暂停游戏时间
        AudioListener.pause = true; // 暂停声音
        isPaused = true;
    }

    // 恢复游戏并隐藏UI菜单
    public void ResumeGame()
    {
        pauseMenuUI.SetActive(false); // 隐藏UI菜单
        Time.timeScale = 1f; // 恢复游戏时间
        AudioListener.pause = false; // 恢复声音
        isPaused = false;
    }
}
